package com.controller;

import java.net.URL;

class KonamiThread {

	public Konami runningThread;
	public static URL[] urls;

	public static void main(String args[]) {
        int multijar = Integer.parseInt(args[0]); //not implemented
		int startLine = Integer.parseInt(args[1]);
		int endLine = Integer.parseInt(args[2]);
		String outputFolder = args[3];
		String inputFile = args[4];
		String report = args[5];
		String browser = args[6];
		urls = Konami.readURLs(inputFile);
		
		KonamiThread t = new KonamiThread();
		t.runningThread = new Konami(startLine,endLine,outputFolder,inputFile,report, browser);
		System.out.println("Starrrt!");
		t.runningThread.start();

		while (Konami.lastA < endLine) {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			if (!t.runningThread.isAlive()) {
				System.out.println("Interrrrrupted");
				t.reportError(Konami.lastA++,Konami.lastLine, outputFolder, inputFile, report, browser);
			}
		}
	}

	public void reportError(int currentLine, int endLine, String outputFolder, String inputFile, String report, String browser) {
		System.out.println("Report Error");
		currentLine++;
		runningThread = new Konami(currentLine,endLine,outputFolder, inputFile, report, browser);
		runningThread.start();
	}
}